package com.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.AdminLog;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryAdminLogDTO;
import com.health.mapper.AdminLogMapper;
import com.health.service.IAdminLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author health
 * @since 2023-04-21
 */
@Service
public class AdminLogServiceImpl extends ServiceImpl<AdminLogMapper, AdminLog> implements IAdminLogService {

    @Override
    public PageData listPageAdminLog(QueryAdminLogDTO queryAdminLogDTO) {
        IPage<AdminLog> iPage = new Page<>(queryAdminLogDTO.getCurrentPage(), queryAdminLogDTO.getPageSize());
        LambdaQueryWrapper<AdminLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(queryAdminLogDTO.getAccount() != null && StringUtils.isNotEmpty(queryAdminLogDTO.getAccount()))
            lambdaQueryWrapper.eq(AdminLog::getUsername, queryAdminLogDTO.getAccount());
        if(queryAdminLogDTO.getStartDate() != null && StringUtils.isNotEmpty(queryAdminLogDTO.getStartDate()))
            lambdaQueryWrapper.gt(AdminLog::getCreateTime, queryAdminLogDTO.getStartDate());
        if(queryAdminLogDTO.getEndDate() != null && StringUtils.isNotEmpty(queryAdminLogDTO.getEndDate()))
            lambdaQueryWrapper.lt(AdminLog::getCreateTime, queryAdminLogDTO.getEndDate());
        IPage<AdminLog> page = baseMapper.selectPage(iPage, lambdaQueryWrapper);
        return new PageData(page.getTotal(), page.getRecords());
    }
}
